<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/view/system/common/headLogin.jsp"%>

<body>
	<form id="form1" name="form1" method="post">
		<input type="hidden" name="userIds" value="${userIds}">
		<input type="hidden" id="setRoleId" name="roleId">
		<input type="hidden" id="setRoleName" name="roleName">
		<table id="userListDataShow">
		</table>
		<br />
		<table id="roleListDataShow"></table>
		<div style="text-align:center;">
			<br />
			<a class="easyui-linkbutton myLink" iconCls="icon-ok"
				onclick="submitForm()">设置 </a> &nbsp;
			<a class="easyui-linkbutton myLink" iconCls="icon-undo"
				onclick="closeForm()">关闭</a>
		</div>
	</form>
</body>

</html>
<!--查看详情 DIALOG-->
<div id="DetailDialog">
	<table id='DetailTable' class="infoTable"
		style="word-break: break-all; word-wrap: break-word;">
	</table>
</div>
<script type="text/javascript">

$('#DetailDialog').dialog( {
	title : "角色信息",
	width : 550,
	top : 30,
	closed : true,
	resizable : true,
	// modal: true,
	buttons : [ {
		text : "关闭",
		iconCls : 'icon-undo',
		handler : function() {
			$('#DetailDialog').dialog('close');
		}
	} ]
});

$(document).ready(function() {
	setRoleListDataGridList();
	setUserListDataGridList();
});

function setUserListDataGridList() {
$('#userListDataShow').datagrid({
		data:${userRoleSetUserList},
		title:"待分配角色的用户列表",
		fitColumns:true,nowrap:false,rownumbers:true,showFooter:false,striped:true,singleSelect:false,
		idField:'id',
		columns:[[{field:'id',width:10,hidden:true,sortable:false}
		,{field:'username',title:"用户名",width:15}
			,{field:'code',title:"工号",width:10,sortable:false}
			,{field:'name',title:"名称",width:20,sortable:false}
			
			,{field:'rolename',title:"角色",width:15,sortable:false}
			,{field:'userstate',title:"状态",width:20,sortable:false,formatter:function(val){return val==0?'正常':(val==1?'已删':'已禁用');}}
		]]
	});
}
function setRoleListDataGridList(){
	$('#roleListDataShow').datagrid({
		url:'role/getRoleList.action',
		title:"角色列表",
		fitColumns:true,nowrap:false,rownumbers:true,showFooter:false,pagination:true,striped:true,singleSelect:true,
		idField:'id',
		frozenColumns:[[{field:'ck',checkbox:true}]],
		toolbar:[
		<%if (SysAuthUtil.ifBtn(request, "roleAdd")) {%>
			{id:'btnadd',text:'增加',iconCls:'icon-add',handler:function(){doRoleAdd();}},'-',
		<%}%>
		{id:'btnrefresh',text:'<s:text name="refresh"/>',iconCls:'icon-reload',handler:function(){$('#roleListDataShow').datagrid('reload');}}
		],
		columns:[[{field:'id',width:10,hidden:true,sortable:false}
			,{field:'name',title:"名称",width:15,sortable:false}
			,{field:'descr',title:"描述",width:20,sortable:false}
			,{field:'state',title:"状态",width:20,sortable:false,formatter:function(val){return val==0?'正常':(val==1?'已删':'已禁用');}}
			,{field:'createtime',title:"添加时间",width:10,sortable:false}
		]]
	});
}

//查看详情
function showDetail(rowData) {
	var DetailTable = $('#DetailTable');
	DetailTable.html('');
	$('#DetailDialog').dialog('open');
}

function doRoleAdd(){
	addTab('角色添加', "view/goViewWithoutData/role_roleAdd.action", '#tt', "parent");
}

function submitForm(){
	var rows = $('#roleListDataShow').datagrid('getSelected');
	if(rows==null){
		$.messager.alert('<s:text name="mes.message"/>', "请选择分配的角色.", 'info');
	} else{
		$("#setRoleId").val(rows.id);
		$("#setRoleName").val(rows.name);
		var param = $('#form1').serializeJson(true);
		//提交后台处理  
		//$.post("doUserRoleSet.action" + param, callbackAdd);
		$.axs("user/doUserRoleSet.action", param, function(data){
			if(data.status == 1){
				$.messager.alert("提示信息", data.msg, 'info', function() {
					closeParentTTTab();
				});
			}else{
				$.messager.alert("错误信息", data.msg, 'error');
			}
		});
	}
}

function closeForm() {
	closeParentTTTab();
}
</script>
